// components/dialog/index.js
Component({
  properties: {
    show: {
      type: Boolean,
    },
    reset: {
      type: Boolean,
      value: false,
      observer(newVal) {
        if (newVal)
        this.resetData();
      },
    }
  },

  data: {
    name: "",
    category: "",
    material: "",
    weight: "",
    length: "",
    width: "",
    height: "",
    year: "",
  },

  lifetimes: {
    attached: function () {
    },
    detached: function () {
    }
  },

  methods: {
    inputName: function(e) {
      this.setData({'name': e.detail.value})
    },
    inputCategory: function(e) {
      this.setData({'category': e.detail.value})
    },
    inputMaterial: function(e) {
      this.setData({'material': e.detail.value})
    },
    inputWeight: function(e) {
      this.setData({'weight': e.detail.value})
    },
    inputLength: function(e) {
      this.setData({'length': e.detail.value})
    },
    inputWidth: function(e) {
      this.setData({'width': e.detail.value})
    },
    inputHeight: function(e) {
      this.setData({'height': e.detail.value})
    },
    inputYear: function(e) {
      this.setData({'year': e.detail.value})
    },
    resetData: function() {
      this.setData({
        name: "",
        category: "",
        material: "",
        weight: "",
        length: "",
        width: "",
        height: "",
        year: ""
      })
    },

    onConfirm: function () {
      // 自定义组件向父组件传值
      const option = {
        name: this.data.name,
        category: this.data.category,
        material: this.data.material,
        weight: this.data.weight,
        length: this.data.length,
        width: this.data.width,
        height: this.data.height,
        year: this.data.year,
      };
      // 用户点击确定按钮的逻辑处理
      this.triggerEvent('confirm', option)
      // this.resetData()
    },
    onCancel: function () {
      // 用户点击取消按钮的逻辑处理
      this.triggerEvent('cancel')
      // this.resetData()
    }
  }
})